<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户登录页</title>
    <link rel="stylesheet" href="css/login.css">
    <link rel="stylesheet" href="css/common.css">
</head>
<body>
    <!-- 页面主体部分 -->
    <div class="login-container">
        <!-- 垂直水平居中的登录对话框 -->
        <div class="login-dialog">
            <!-- 登录对话框的头部信息 -->
            <div class="header">            
                <span>用户登录</span>
                <div class="space"></div>
                <span>没有账号,去<a href="register.html">注册</a></span>
            </div>
            <!-- 登录对话框的登录部分 -->
            <div class="login-part">
                <h3>欢迎登录</h3>
                <div class="row">
                    <span>账号：</span>
                    <input type="text" id="username" name="username">
                </div>
                <div class="row">
                    <span>密码：</span>
                    <input type="password" id="password" name="password">
                </div>
                <div class="row">
                    <button id="submit" onclick="mysub()">登录</button>
                </div>
            </div>
        </div>
    </div>
</body>
<!-- 引入jquery -->
<script src="js/jqurery.min.js"></script>
<script>
    function mysub(){
        let username = jQuery("#username");
        let password = jQuery("#password");

        if(username.val().trim() == ""){
            alert("请输入用户名！");
            username.focus();
            return false;
        }
        if(password.val().trim() == ""){
        alert("请输入密码！");
        password.focus();
        return false;
        }
        jQuery.ajax({
            url:"/user/login",
            type:"POST",
            data:{
                "username":username.val().trim(),
                "password":password.val().trim()
            },
            success(res){
                if(res.code == 200 && res.data == 1){
                    alert("登陆成功，跳转聊天主页！");
                    location.href = "client.html";
                }else{
                    alert("抱歉：登录失败！ " + res.message);
                }
            }
        });
    }
</script>
</html>